$(function() {
	
	var removeChildNodes = function($, own) {
			if ($ == null) {
				return;
			}
			while ($.hasChildNodes()) {
				$.removeChild($.firstChild);
			}
			if (own) {
				$.parentNode.removeChild($);
			}
	};
	//获取主分类和主分类下的子分类ID
	var pageContext = {
			mainTypeId :0,
			childTypeId :1,
			page:1,
			allChildType:1,
			a:1
	}
	
	
	
	//点击显示视频ID
	$(".mate-cate").on('click',function(){
		$.ajax({		 
        type:"GET",        
        url:$url+'/type/getMainType/'+pageContext.mainTypeId,        
        dataType:"json",
        success: function(result) {        	
      		var items = result.data.list;			
  		  	$.each(items, function(i,value){
			  		$(".msg-list-m").append(
			  			'<li>'+value.mainTypeName+
			  			'</li>'
			  		);
  		  		});
  		  		
	  			$(this).attr("id",value.mainTypeId);
	  			$(this).siblings().removeAttr("id");
	  			pageContext.mainTypeId=$(this).attr("id");
	  			alert(pageContext.mainTypeId);
		    },
		     error:function(jqXHR){     
		       alert("发生错误：" + jqXHR.status)  
		    }
	})
})

	$("#pic").on('change', function() {
		document.getElementById("Video").style.display = "block";
		document.getElementsByClassName("uploading-bd")[0].style.display = "none";
	})
	
	$(".progress-icon").on('click',function(){
		document.getElementById("Video").style.display = "none";
		document.getElementsByClassName("uploading-bd")[0].style.display = "block";
	})

	$(".course-title-li").click(function() {
		$(this).addClass("active").siblings().removeClass("active");
		var index = $(".course-title-li").index(this);
		$(".course-content-list").eq(index).show().siblings().hide();
	})
	$(".mate-cate").on('click', function() {
		if ($('.mate-cate-list').is(':hidden')) {
			$('.mate-cate-list').show();
		} else {
			$('.mate-cate-list').hide();
		}
	})

	$(".msg-box-1 li").click(function() {
		var index = $(".msg-box-1 li").index(this); //课程方向的li的索引
		var bbb = $(this).html();
		var isSep = $(".course-title-li").attr('data-sep');
		if (isSep == 'yes') {
			$(".jump").addClass("active").siblings().removeClass("active");
			$(".course-content-list").eq(index + 1).show().siblings().hide();
			$(".course-content-list").eq(index + 1).find('li').click(function() {
				$(".mate-cate span").html(bbb + $(this).html());
				$(".mate-cate-list").css("display", "none");
			})
		}
	})

	//隐私
	var isNum = 1;
	$(".jump").click(function() {
		isNum++;
		if (isNum != 1) {
			$(".course-content-list").css("display", "none");
		}
	})

	$(".secret").on('click', function() {
		if ($('.secret-msg').is(':hidden')) {
			$('.secret-msg').show();
		} else {
			$('.secret-msg').hide();
		}
	})

	$(".secret-msg ul li").on('click', function() {
		$(".secret span").html($(this).html());
		$('.secret-msg').hide();
	})

	//收费
	$(".charge").on('click', function() {
		if ($('.charge-msg').is(':hidden')) {
			$('.charge-msg').show();
		} else {
			$('.charge-msg').hide();
		}
	})

	$(".charge-msg ul li").on('click', function() {
		$(".charge span").html($(this).html());
		$('.charge-msg').hide();
	})

	//同步
	$(".cogradient").on('click', function() {
		if ($('.cogradient-msg').is(':hidden')) {
			$('.cogradient-msg').show();
		} else {
			$('.cogradient-msg').hide();
		}
	})

	$(".cogradient-msg ul li").on('click', function() {
		$(".cogradient span").html($(this).html());
		$('.cogradient-msg').show();
	})

	//原创
	$(".original").on('click', function() {
		if ($('.original-msg').is(':hidden')) {
			$('.original-msg').show();
		} else {
			$('.original-msg').hide();
		}
	})

	$(".original-msg ul li").on('click', function() {
		$(".original span").html($(this).html());
		$('.original-msg').hide();
	})

	//标签		
	$(".label-list span a").on('click', function() {
	//var aa = $(this).html();
		var _index = $(".label-list span").index(this);
		$(".video-label").html("");
		$('<div class="video-label-list">' + aa + '<p class="video-p"></p></div>').appendTo(".video-label");
	})
	
	//点击保存接口
	$(".keep-title").on('click',function(){
			if($(".secret").html() == "公开"){
				publishFlag=1;
			}else{
				publishFlag=0;
			}
			
			$.ajax({ 
	        type:"POST",
	        dataType:"json",
	        url:'http://192.168.0.12:8080/elink_video/video/submitMedia?videoStorageId='+videoStorageId+'&seed='+getAuth().seed+'&authToken='+getAuth().authToken+'',
	        contentType:'application/json;charset=UTF-8',
	        data:		        	
	        	JSON.stringify({
		        	introduction:$(".abstract input").val(),
		        	videoSourceName:$("#form-input").val(),				        	
		        	describes:$(".textarea-item textarea").val(),
					publishFlag:publishFlag,
					childType:$("#childType .option").val()
	        	}),
	        	//公開 1  publishFlag
	        	//私密  0
	        beforeSend: function () {
				$(".msg-phone-icon").css("display","none");							
			},
	        success: function(result) {	
			//alert("#1="+videoStorageId)			        	
	             if (result.code == 2050) {
	             	alert("成功");
	            	$("#phone").css("border","1px solid #ddd");
   					$("span#phone_error").css("color","#ddd");
	            } else {
	            	alert("失败");
	            	$("#authcode").css("border","1px solid red");
   					$("span#mail_error").css("color","red");
					$("span#authcode_error").html("");
	            } 
	        },
	         error:function(jqXHR){     
	           alert("发生错误：" + jqXHR.status)  
	        } 
	    });
	    
			
		var childTypeElement = document.getElementById("childType");
		var childtypeIdElement = document.getElementById("childTypeId");
		if (childTypeElement.value == 0) {
			alert("请选择分类");
			return;
		}
		var childTypeId = childtypeIdElement.value;
		alert("请求的参数为childTypeId="+childTypeId);
		return;
		
		
		
	
		}
	)
	
	
});

